#pragma config(Sensor, dgtl1,  rightEncoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  leftEncoder,    sensorQuadEncoder)
#pragma config(Sensor, dgtl5,  rightLimit,     sensorTouch)
#pragma config(Sensor, dgtl6,  leftLimit,      sensorTouch)
#pragma config(Sensor, dgtl7,  sonar,          sensorSONAR_cm)
#pragma config(Motor,  port2,           rightMotor,    tmotorVex269, openLoop)
#pragma config(Motor,  port3,           leftMotor,     tmotorVex269, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
void forward(int revs){
  SensorValue[rightEncoder]=0;
  SensorValue[leftEncoder]=0;
  int turns=revs*360;
  while(SensorValue[rightEncoder]<turns){
    if(SensorValue[rightEncoder]>SensorValue[leftEncoder]){
      motor[rightMotor]=60;
      motor[leftMotor]=80;
    }
    else if(SensorValue[leftEncoder]>SensorValue[rightEncoder]){
      motor[leftMotor]=80;
      motor[rightMotor]=60;
      }
      else if(SensorValue[rightEncoder]==SensorValue[leftEncoder]){
        motor[rightMotor]=80;
        motor[leftMotor]=80;
      }
    }
    }
void turnright(){
  SensorValue[rightEncoder]=0;
  SensorValue[leftEncoder]=0;
  while(SensorValue[leftEncoder]<50){
    motor[rightMotor]=-60;
    motor[leftMotor]=40;
  }
}
void turnleft(){
  SensorValue[rightEncoder]=0;
  SensorValue[leftEncoder]=0;
  while(SensorValue[rightEncoder]>50){
    motor[rightMotor]=40;
    motor[leftMotor]=-60;
  }
}

task main(){
  if(SensorValue[leftLimit]==0 && SensorValue[rightLimit]==0){
  forward(10);
}
  else if(SensorValue[leftLimit]==1){
  turnright();
}
  else if(SensorValue[rightLimit]==1){
  turnleft();
}
}
